package stack;

import java.util.ArrayList;

public class Stack<T> {
	private ArrayList<T> arr;
	int stackPtr;
	
	Stack() {
		arr = new ArrayList<T>();
		stackPtr = -1;
	}
	
	void push(T elem) {
		stackPtr++;
		if (arr.size() <= stackPtr) {
			arr.add(elem);
		} else {
			arr.set(stackPtr, elem);
		}
	}
	
	T pop() {
		T elem = arr.get(stackPtr);
		stackPtr--;
		return elem;
	}
}
